package com.yun.algorithmproblem.leetcode;

import java.util.ArrayList;
import java.util.List;

public class Leetcode1472 {

    public static void main(String[] args) {
        BrowserHistory obj=new BrowserHistory("leetcode.com");
        obj.visit("google.com");
        obj.visit("facebook.com");
        obj.visit("youtube.com");
        System.out.println(obj.back(1));
    }

    static class BrowserHistory {

        List<String> history;
        int curr;

        public BrowserHistory(String homepage) {
            history = new ArrayList<>();
            history.add(homepage);
            curr = 0;
        }

        public void visit(String url) {
            history = history.subList(0, curr+1);
            history.add(url);
            curr++;
        }

        public String back(int steps) {
            curr = Math.max(curr - steps, 0);
            return history.get(curr);
        }

        public String forward(int steps) {
            curr = Math.min(curr+steps, history.size()-1);
            return history.get(curr);
        }
    }
}
